<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item label="分销商" prop="useruuid">
					<el-select v-model="filters.downId" clearable placeholder="请选择分销商" filterable >
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in users"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="供货商" prop="useruuid"  >
					<el-select v-model="filters.upId" clearable placeholder="请选择供货商" filterable filterable >
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in userUps"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="datetime" placeholder="开始时间"  format="yyyy-MM-dd HH:mm:ss" clearable  v-model="filters.startTime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="datetime" placeholder="结束时间" clearable format="yyyy-MM-dd HH:mm:ss"   v-model="filters.endTime" style="width: 100%;"></el-date-picker>
				</el-form-item>

				<el-form-item>
					<el-button type="primary" v-on:click="getBlacklistPage">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="mobiles" highlight-current-row v-loading="listLoading" border max-height="620" style="width: 100%;">
			<el-table-column type="index" width="80" label="编号">
			</el-table-column>
			<el-table-column prop="username" label="分销渠道"  >
			</el-table-column>
			<el-table-column prop="downfacevalue" label="分销面值"  >
			</el-table-column>
			<el-table-column prop="discountDown" label="分销折扣"  >
			</el-table-column>
			<el-table-column prop="upname" label="供货渠道"  >
			</el-table-column>
			<el-table-column prop="discountUp" label="供货折扣"  >
			</el-table-column>
		</el-table>
		<el-pagination
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>



	</section>
</template>

<script>
	import util from '../../common/js/util'
	import { getProductDiscount ,findAllUpShopInfo,findAllDownShopInfo} from '../../api/api';
	import moment from 'moment';
	export default {
		data() {
			return {
				filters: {
					startTime: moment().subtract('hour', 3).format('YYYY-MM-DD HH:mm:ss') ,
					endTime: moment(new Date(),"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD') + " 23:59:59",
					upId:'',
					downId:''
				},
                users: [],
				mobiles:[],
				userUps:[],
                total: 0,
                start:0,
                pageSize:10,
				listLoading: false,
			}
		},
		methods: {
			findAllDownShopInfo:function(){
				let para = {useruuid: JSON.parse(sessionStorage.getItem("user")).useruuid};
				findAllDownShopInfo(para).then(datas => {
					let {message, code, data} = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						if(data){
							this.users = data;
						}
					}
				});
			},
			findAllUpShopInfo:function(){
				let para = {
					test:''
				};
				findAllUpShopInfo(para).then(datas =>{
					let {message, code, data} = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						this.userUps = data;
					}
				});
			},
			getBlacklistPage() {
                let para = {
                    start: this.start,
                    pageSize:this.pageSize,
					startTime:this.filters.startTime == undefined ? "" : this.filters.startTime,
					endTime:this.filters.endTime == undefined ? "" : this.filters.endTime,
					upId:this.filters.upId,
					downId:this.filters.downId,
                };
                this.listLoading = true;
				getProductDiscount(para).then((datas) => {
                    this.listLoading = false;
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.mobiles = data.result;
                        this.total = data.totalCount;
                    }
                });
			}
			,handleCurrentChange:function(val){
				this.start = val - 1;
				this.getBlacklistPage();
			},
			handleSizeChange:function(val){
				this.pageSize = val;
				this.getBlacklistPage();
			}
		},
		mounted() {
			this.findAllDownShopInfo();
			this.findAllUpShopInfo();
			this.getBlacklistPage();
		}
	}

</script>

<style scoped>

</style>
